package ynu.beggar.server.entities.PO;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import ynu.beggar.server.entities.DO.ForumPostCreateDO;
import ynu.beggar.server.entities.DO.UserBasicInfoDO;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "forum_post", schema = "ynu_beggar")
public class ForumPostPO {
    private int postId;
    private Integer userId;
    private String userName;
    private String postType;
    private String title;
    private String keyWord;
    private String campus;
    private String foodDescription;
    private String outAddress;
    private String inAddress;
    private String content;
    private String pictureUrl;
    private LocalDateTime createTime;
    private LocalDateTime appointedTime;
    private Integer agreeNum;
    private Integer disagreeNum;
    private Integer del;

    public ForumPostPO(ForumPostCreateDO forumPostCreateDO, UserBasicInfoDO userBasicInfoDO) {
        this.userId = userBasicInfoDO.getUserId();
        this.userName = userBasicInfoDO.getUserName();
        this.postType = forumPostCreateDO.getPostType();
        this.title = forumPostCreateDO.getTitle();
        this.keyWord = forumPostCreateDO.getKeyWord();
        this.campus = forumPostCreateDO.getCampus();
        this.foodDescription = forumPostCreateDO.getFoodDescription();
        this.outAddress = forumPostCreateDO.getOutAddress();
        this.inAddress = forumPostCreateDO.getInAddress();
        this.content = forumPostCreateDO.getContent();
        this.pictureUrl = forumPostCreateDO.getPictureUrl();
        this.createTime = LocalDateTime.now();
        this.appointedTime = LocalDateTime.parse(forumPostCreateDO.getAppointedTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "post_id")
    public int getPostId() {
        return postId;
    }

    public void setPostId(int postId) {
        this.postId = postId;
    }

    @Basic
    @Column(name = "user_id")
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "user_name")
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Basic
    @Column(name = "post_type")
    public String getPostType() {
        return postType;
    }

    public void setPostType(String postType) {
        this.postType = postType;
    }

    @Basic
    @Column(name = "title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "key_word")
    public String getKeyWord() {
        return keyWord;
    }

    public void setKeyWord(String keyWord) {
        this.keyWord = keyWord;
    }

    @Basic
    @Column(name = "campus")
    public String getCampus() {
        return campus;
    }

    public void setCampus(String campus) {
        this.campus = campus;
    }

    @Basic
    @Column(name = "food_description")
    public String getFoodDescription() {
        return foodDescription;
    }

    public void setFoodDescription(String foodDescription) {
        this.foodDescription = foodDescription;
    }

    @Basic
    @Column(name = "out_address")
    public String getOutAddress() {
        return outAddress;
    }

    public void setOutAddress(String outAddress) {
        this.outAddress = outAddress;
    }

    @Basic
    @Column(name = "in_address")
    public String getInAddress() {
        return inAddress;
    }

    public void setInAddress(String inAddress) {
        this.inAddress = inAddress;
    }

    @Basic
    @Column(name = "content")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Basic
    @Column(name = "picture_url")
    public String getPictureUrl() {
        return pictureUrl;
    }

    public void setPictureUrl(String pictureUrl) {
        this.pictureUrl = pictureUrl;
    }

    @Basic
    @Column(name = "create_time")
    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "appointed_time")
    public LocalDateTime getAppointedTime() {
        return appointedTime;
    }

    public void setAppointedTime(LocalDateTime appointedTime) {
        this.appointedTime = appointedTime;
    }

    @Basic
    @Column(name = "agree_num")
    public Integer getAgreeNum() {
        return agreeNum;
    }

    public void setAgreeNum(Integer agreeNum) {
        this.agreeNum = agreeNum;
    }

    @Basic
    @Column(name = "disagree_num")
    public Integer getDisagreeNum() {
        return disagreeNum;
    }

    public void setDisagreeNum(Integer disagreeNum) {
        this.disagreeNum = disagreeNum;
    }

    @Basic
    @Column(name = "del")
    public Integer getDel() {
        return del;
    }

    public void setDel(Integer del) {
        this.del = del;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ForumPostPO that = (ForumPostPO) o;

        if (postId != that.postId) return false;
        if (userId != null ? !userId.equals(that.userId) : that.userId != null) return false;
        if (userName != null ? !userName.equals(that.userName) : that.userName != null) return false;
        if (postType != null ? !postType.equals(that.postType) : that.postType != null) return false;
        if (title != null ? !title.equals(that.title) : that.title != null) return false;
        if (keyWord != null ? !keyWord.equals(that.keyWord) : that.keyWord != null) return false;
        if (campus != null ? !campus.equals(that.campus) : that.campus != null) return false;
        if (foodDescription != null ? !foodDescription.equals(that.foodDescription) : that.foodDescription != null)
            return false;
        if (outAddress != null ? !outAddress.equals(that.outAddress) : that.outAddress != null) return false;
        if (inAddress != null ? !inAddress.equals(that.inAddress) : that.inAddress != null) return false;
        if (content != null ? !content.equals(that.content) : that.content != null) return false;
        if (pictureUrl != null ? !pictureUrl.equals(that.pictureUrl) : that.pictureUrl != null) return false;
        if (createTime != null ? !createTime.equals(that.createTime) : that.createTime != null) return false;
        if (appointedTime != null ? !appointedTime.equals(that.appointedTime) : that.appointedTime != null)
            return false;
        if (agreeNum != null ? !agreeNum.equals(that.agreeNum) : that.agreeNum != null) return false;
        if (disagreeNum != null ? !disagreeNum.equals(that.disagreeNum) : that.disagreeNum != null) return false;
        if (del != null ? !del.equals(that.del) : that.del != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = postId;
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + (postType != null ? postType.hashCode() : 0);
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (keyWord != null ? keyWord.hashCode() : 0);
        result = 31 * result + (campus != null ? campus.hashCode() : 0);
        result = 31 * result + (foodDescription != null ? foodDescription.hashCode() : 0);
        result = 31 * result + (outAddress != null ? outAddress.hashCode() : 0);
        result = 31 * result + (inAddress != null ? inAddress.hashCode() : 0);
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (pictureUrl != null ? pictureUrl.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (appointedTime != null ? appointedTime.hashCode() : 0);
        result = 31 * result + (agreeNum != null ? agreeNum.hashCode() : 0);
        result = 31 * result + (disagreeNum != null ? disagreeNum.hashCode() : 0);
        result = 31 * result + (del != null ? del.hashCode() : 0);
        return result;
    }
}
